import { Entity, PrimaryGeneratedColumn, Column, Index } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";

export enum HouseTrainingType {
  Library = "LIBRARY", // 书房练书
  Alchemy = "ALCHEMY", // 炼丹房炼丹
  Gongfang = "GONGFANG", // 功房副将心法
}

@Entity("house_training_tasks")
@ManualTimestamp()
export class HouseTrainingTaskEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Index()
  @Column("int", { name: "characterId" })
  characterId!: number;

  @Column("varchar", { length: 16, comment: "训练类型：LIBRARY/ALCHEMY" })
  type!: HouseTrainingType;

  @Column("int", { default: 0, comment: "技能书等级(1-5)，炼丹固定为0" })
  level!: number;

  @Column("int", { default: 1, comment: "产出数量，默认1" })
  count!: number;

  @Column("int", {
    default: 0,
    comment: "产出物品ID（炼丹用，书房根据level映射）",
  })
  itemId!: number;

  @Column("int", {
    name: "duration_minutes",
    default: 0,
    comment: "训练时长(分钟)",
  })
  durationMinutes!: number;

  @Column("datetime", { name: "start_at", nullable: true, comment: "开始时间" })
  startAt!: Date | null;

  @Column("datetime", { name: "end_at", nullable: true, comment: "结束时间" })
  endAt!: Date | null;

  @Column("int", { default: 0, comment: "消耗金砖" })
  costGold!: number;

  @Column("int", {
    name: "status",
    default: 0,
    comment: "状态：0-已创建，1-进行中，2-已完成，3-失败",
  })
  status!: number;

  @Column("varchar", { length: 255, default: "", comment: "备注/失败原因" })
  remark!: string;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", {
    name: "updated_at",
    nullable: true,
    comment: "更新时间",
  })
  updated_at!: Date | null;
}
